package cn.sylinx.web.map;

import io.vertx.core.Handler;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.RoutingContext;

public interface RequestMapping {

	/**
	 * 映射路径
	 * 
	 * @return 映射路径
	 */
	public String path();

	/**
	 * 请求方法
	 * 
	 * @return 请求方法
	 */
	public HttpMethod[] method();

	/**
	 * 处理事件
	 * 
	 * @param context
	 *            RoutingContext
	 */
	public Handler<RoutingContext> handle();

	/**
	 * 错误处理
	 * 
	 * @param context
	 *            RoutingContext
	 */
	public default Handler<RoutingContext> failureHandler() {

		return new Handler<RoutingContext>() {
			@Override
			public void handle(RoutingContext context) {

				HttpServerResponse response = context.response();
				response.putHeader("content-type", "text/html;charset=UTF-8");
				response.end("出现异常了");
			}
		};

	}
}
